<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../resources/accessibility-helper.js"></script>
</head>
<body>

<fieldset id="fieldset">
    <legend>Choose a shipping method:</legend>
    <div role="group"><input id="overnight" type="radio" name="shipping" value="overnight" />Overnight</div>
</fieldset>

<div>End of test</div>

<p id="description"></p>
<div id="console"></div>

<script>

    description("This tests that a fieldset's title ui element is the legend.");

    if (window.accessibilityController) {
        var fieldset = accessibilityController.accessibleElementById("fieldset");
        var titleUIElement = fieldset.nameElementAtIndex(0);

        // Print out the tree of accessible objects, indicating the titleUIElement so
        // that each platform can verify their expected object has been found
        buildAccessibilityTree(fieldset, 0, 0, 0, titleUIElement, "<< fieldset's titleUIElement");

        // Verify that we have gotten the titleUIElement and it has the expected text,
        // which should be in the last descendant regardless of platform.
        shouldBeTrue("titleUIElement != null");
        var titleUIElementText = titleUIElement;
        while (titleUIElementText && titleUIElementText.childrenCount)
            titleUIElementText = titleUIElementText.childAtIndex(0);

        shouldBe("titleUIElementText.name", "'Choose a shipping method:'");
    }
</script>

</body>
</html>
